
<html>
    <head>
    </head>
    <?PHP
    require 'connect.inc';
    require 'session.inc';
    $res ="";
    if ($_SESSION["isLogin"] == 1) {
        $res = "Wellcom <a href='#'>" . $_SESSION["username"] . "</a>!
                |
                <a href='logout.php'>Logout</a>
                <hr>";

        $res .= " <p> List department:</p>";
        $strSQL = "SELECT d.department_id, d.department_name,
                            (SELECT COUNT(user_id) 
                            FROM users us
                            WHERE us.department_id = d.department_id) as SumUser
                    FROM departments d";
        $result = mysql_query($strSQL);
        if (!$result)
            $res .= "Department is empty!";
        else {
            $res .= "<table class='f11' border='1'>
                    <tr>
                        <th>STT</th>
                        <th>Department  ID</th>
                        <th>Department  name</th>
                        <th>Number  of  users</th> 
                       </tr>";
            $stt = 0;
            while ($row = mysql_fetch_array($result)) {
                $stt++;
                $id = $row["department_id"];
                $name = $row["department_name"];
                $sum = $row["SumUser"];
                $res .= "<tr>
                    <td>$stt</td>
                    <td>$id</td>
                    <td>$name</td>
                    <td><a href='#' onclick='showUsers($id,2)'>$sum</a></td>
               </tr>";
            }
            $res .= "</table>";
            $res .= " <p> List department:</p>";
        }
        $strSQL = "SELECT c.country_id, c.country_name,
                            (SELECT COUNT(user_id) 
                            FROM users us
                            WHERE us.country_id = c.country_id) as SumUser
                    FROM countries c";
        $result = mysql_query($strSQL);
        if (!$result)
            $res .= "Department is empty!";
        else {
            $res .= "<table class='f11' border='1'>";
            $res .= "<tr>
                        <th>STT</th>
                        <th>Country  ID</th>
                        <th>Country  name</th>
                        <th>Number  of  users</th> 
                       </tr>";
            $stt = 0;
            while ($row = mysql_fetch_array($result)) {
                $stt++;
                $id = $row["country_id"];
                $name = $row["country_name"];
                $sum = $row["SumUser"];
                $res .= "<tr>
                    <td>$stt</td>
                    <td>$id</td>
                    <td>$name</td>
                    <td><a href='#' onclick='showUsers($id,1)'>$sum</a></td>
               </tr>";
            }
            $res .= "</table>";
        }
    } else {

        $res .= "<a href='register.php'>Register</a>
    |
    <a href='login.php'>Login</a>
    <hr>        ";
    }
    echo $res;
    ?>

</html>